import 'package:shared_preferences/shared_preferences.dart';

/*
shared_preferences: ^2.0.15
* */

class Cache {
  static late SharedPreferences _prefs;

  static Future<void> init() async {
    _prefs = await SharedPreferences.getInstance();
  }

  static Future<void> set(String key, String value) async {
    if (_prefs == null) {
      throw Exception('[B] Cache 未初始化');
    }
    await _prefs.setString(key, value);
  }

  static String? get(String key) {
    if (_prefs == null) {
      throw Exception('[B] Cache 未初始化');
    }
    return _prefs.getString(key);
  }

  static void del(String key) {
    if (_prefs == null) {
      throw Exception('[B] Cache 未初始化');
    }
    _prefs.remove(key);
  }
}
